import {
    getListDetail,
    getTableLsit,
    submitRemark,
    getCard,
    exportData
} from '@/services/api';
import { message } from 'antd';
export default {
    namespace: 'buyoutes',
    state: {
        tableList: []
    },
    effects: {
        //获取买断订单table列表信息
        * getTableList({ payload, callback }, { put, call }) {
            const response = yield call(getTableLsit, payload);
            if (response.code == 1) {
                yield put({
                    type: 'tableList',
                    payload: response.data
                })
            }
        },
        //新增备注
        * pushRemark({ payload, callback }, { put, call }) {
            const res = yield call(submitRemark, payload);
            if (res.code) {
                res.code === 1 ? message.success('备注成功') : message.error(res.data.msg);
                callback(res);
            }
        },
        //获取证件信息
        * getCardinformation({ payload, callback }, { call }) {
            const res = yield call(getCard, payload);
            if (res.data.code == 1) {
                callback(res.data.data)
            }
        },
        //导出文件
        * exportData({ payload, callback }, { call }) {
            const res = yield call(exportData, payload);
            if (res) {
                message.destroy();
                message.success('导出成功');
                callback(res);
            }
            else {
                message.destroy();
                message.error('导出错误，请重试~');
            }
        }
    },
    reducers: {
        tableList(state, { payload }) {
            return {
                ...state,
                tableList: payload.records
            }
        },
    }
}
